﻿using Common.Infrastructure;
using Core.Infrastructure.StructureMap;
using GemBox.Spreadsheet;
using Sanelib.Initialization;
using StructureMap;
using WebApp.Initialization;
using WebApp.Initialization.Automapper;

namespace IntegrationTests
{
    public class AppStartUp
    {
        private static bool _initialized;
        private static readonly object Lock = new object();

        private AppStartUp() { }

        public static void Initialize()
        {
            if (_initialized) return;
            lock (Lock)
            {
                if (_initialized) return;
                ConfigureStructureMap();
                _initialized = true;
            }
        }      

        private static void ConfigureStructureMap()
        {
            ObjectFactory.Initialize(x => x.Scan(scan =>
            {
                scan.TheCallingAssembly();
                scan.AssemblyContainingType<SanelibRegistry>();
                scan.AssemblyContainingType<CommonRegistry>();
                scan.AssemblyContainingType<CoreRegistry>();
                scan.AssemblyContainingType<UiRegistry>();
                scan.WithDefaultConventions();
                scan.LookForRegistries();
            }));

            AutoMapperConfiguration.Configure(ObjectFactory.GetInstance);

            SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
        }             
    }
}
